Skip to content

add validation for name and description for model model group and connector resources #3805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 15, 2025

Conversation

dhrubo-os
Copy link
Collaborator

@dhrubo-os dhrubo-os commented Apr 29, 2025

add validation for name and description for model model group and connector resources

Description

resolved #3639

Integ test will fail as code coverages is failing for previously merged PR.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.


if (modelName != null && !isSafeText(modelName)) {
exception = addValidationError(
"Model connector name can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.)",
Copy link
Collaborator

@ylwu-amzn ylwu-amzn Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is different with MLUpdateConnectorRequest.java one. Should we keep them consistent ?

"Model connector name can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.). Max length: 1000 characters.",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in the next revision I kept it consistent.


if (modelName != null && !isSafeText(modelName)) {
exception = addValidationError(
"Model connector name can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.). Max length: 1000 characters.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see where validate Max length: 1000 characters." , Is that built-in logic in isSafeText?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I removed that restriction from the regex. But then I forgot to remove that from the error message.

Initially I was thinking to provide 1000 characters restriction.

What do you think? Should we add such kind of restriction?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the comment, find that internal logic in isSafeText

String modelName = updateModelInput.getName();
String description = updateModelInput.getDescription();

if (modelName != null && !isSafeText(modelName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar checking in multiple places ? Can we build some common util method ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that and felt too lazy to refactor 😄. But I fixed it in the second revision. Thanks for insisting on the highest standards!

@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 17:31 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 17:31 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 17:31 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 17:31 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env May 14, 2025 18:35 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env May 14, 2025 18:35 — with GitHub Actions Error
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 19:46 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 19:46 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env May 14, 2025 19:46 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env May 14, 2025 19:46 — with GitHub Actions Error
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 20:31 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env May 14, 2025 20:31 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env May 14, 2025 21:34 — with GitHub Actions Error
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env May 14, 2025 21:34 — with GitHub Actions Failure
@dhrubo-os dhrubo-os merged commit f6a25f5 into opensearch-project:main May 15, 2025
12 of 14 checks passed
@chloewqg
Copy link

Hello! Do we also consider adding / in model name. Currently I am not able to create and register a local model:

POST /_plugins/_ml/models/_register
{
  "name": "huggingface/sentence-transformers/msmarco-distilbert-base-tas-b",
  "version": "1.0.2",
  "model_group_id": "Z1eQf4oB5Vm0Tdw8EIP2",
  "model_format": "TORCH_SCRIPT"
}

{
	"error": {
		"root_cause": [
			{
				"type": "action_request_validation_exception",
				"reason": "Validation Failed: 1: Model name can only contain letters, numbers, whitespace, and basic punctuation (.,!?():@-_'\");"
			}
		],
		"type": "action_request_validation_exception",
		"reason": "Validation Failed: 1: Model name can only contain letters, numbers, whitespace, and basic punctuation (.,!?():@-_'\");"
	},
	"status": 400
}

akolarkunnu pushed a commit to akolarkunnu/ml-commons that referenced this pull request Jun 6, 2025
…nector resources (opensearch-project#3805)

* add validation for name and description for model model group and connector resources

Signed-off-by: Dhrubo Saha <[email protected]>

* addressing comment, added a common method in utils to remove code redundnancy

Signed-off-by: Dhrubo Saha <[email protected]>

* making more flexible the regex pattern

Signed-off-by: Dhrubo Saha <[email protected]>

* removing restriction of 1000 characters

Signed-off-by: Dhrubo Saha <[email protected]>

* addressing comments

Signed-off-by: Dhrubo Saha <[email protected]>

* fixing unit test messages

Signed-off-by: Dhrubo Saha <[email protected]>

* fixing unit test assertion

Signed-off-by: Dhrubo Saha <[email protected]>

* adding a generic way so that we can check for optional or required field too

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
Signed-off-by: Abdul Muneer Kolarkunnu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Enhance Input Validation for UpdateModel and UpdateModelGroup APIs
7 participants